<?php 
if(!defined('IN_CAI')) {
	exit('Access Denied');
}
/**
 * 祝福管理
 * 
 */
$ac = $_REQUEST['ac'];
$url = '/admin/index.php?do=pray';
if (empty($ac)) {
	$ac = 'list';
}
if ($ac == 'list') {
	$page = intval($_GET['page']) >0 ? intval($_GET['page']) : 1;
	$limit = 20;
	$offset = ($page - 1) *$limit;
	$keyword = trim($_GET['keyword']);
	if (!empty($keyword)) {
		$where = "where content like '%$keyword%' ";
	}
	$count = $db->result($db->query("select count(*) from ".tname('pray')." $where"),0);
	$query = $db->query("select * from ".tname('pray')." $where order by id desc limit $offset,$limit");
	$list = $db->fetch_all($query);
	$pagestr = multi($count,$limit,$page,$url);
	include atemplate('do_pray_list');
} elseif ($ac == 'edit') {
	
	if (empty($_POST['step'])) {
		$id = intval($_GET['id']);
		$query = $db->query("select * from ".tname('pray')." where id = $id");
		$info = $db->fetch_array ($query);
		if (empty($info)) {
			adminmessage('对不起，找不到改信息');	
		}
		include atemplate('do_pray_add');
	}else {
		$id = intval($_POST['id']);
		$content = trim($_POST['content']);
		$data['content'] = $content;
		updatetable('pray',$data,array('id'=>$id));
		adminmessage('修改祝福成功',$url);
	}
}elseif ($ac == 'del') {
	$id = intval($_GET['id']);
	if (!id) {
		adminmessage('非法ID');
	} else {
		$db->query('delete from '.tname('pray').' where id='.$id);
		if ($db->affected_rows()) {
			adminmessage('删除祝福成功',$url);
		}else {
			adminmessage('删除祝福失败',$url);
		}
	}
}
?>